package cn.itcast.com.exception;

public class zidingyo {
    public static void main(String[] args) throws CheckableScoreException {
        recordScore(-1);
    }
    //既可以编译异常也可以运行时异常
    public static void recordScore(int score) throws CheckableScoreException {
        if(score < 0 || score > 100){
            //分数异常，抛出异常，向上报告
            //runtimeScoreException runtimeScoreException = new runtimeScoreException("分数非法" + score);
            //抛出运行时异常
            //throw new runtimeScoreException("runtime分数非法"+score);
            //抛出编译时异常
            throw  new CheckableScoreException("分数非法"+score);
        }
    }
}

//自定义运行时异常
class runtimeScoreException extends RuntimeException{
    //可以添加构造方法，一个参数

    public runtimeScoreException(String message) {
        super(message);
    }
}

//自定义编译时异常
class CheckableScoreException extends Exception{
    //同上添加

    public CheckableScoreException(String message) {
        super(message);
    }
}